package com.itboye.eweilisten.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.me.home.ActivityExperience;
import com.itboye.eweilisten.me.personal.activity.ActivityBooks;
import com.itboye.eweilisten.model.GuessBooks;
import com.itboye.eweilisten.presenter.UserPresenter;
import com.itboye.eweilisten.util.loadingutil.MAlert;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.widget.XImageLoader;
import com.itboye.eweilisten.volley.ResultEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import static com.itboye.eweilisten.base.BaseActivity.EVENT_TYPE_UNKNOWN;

/**
 * Created by YJY on 2017/8/28.
 */

public class GuessLikeAdapter extends BaseAdapter {

    Context context;
    List<GuessBooks.ListInfo> listGuessInfo;


    public GuessLikeAdapter(Context context, List<GuessBooks.ListInfo> listGuessInfo) {
        this.context = context;
        this.listGuessInfo = listGuessInfo;
    }

    @Override
    public int getCount() {
        return listGuessInfo.size() > 3 ? 3 : listGuessInfo.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_guess_like, null);
            viewHolder.guessBook = (ImageView) convertView.findViewById(R.id.iv_guessBook);
            viewHolder.guessName = (TextView) convertView.findViewById(R.id.tv_guessName);
            viewHolder.guessPrice = (TextView) convertView.findViewById(R.id.tv_guessPrice);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.guessName.setText(listGuessInfo.get(position).getName());
        viewHolder.guessPrice.setText("¥"+Integer.valueOf(listGuessInfo.get(position).getMin_price())/100+".00");
        XImageLoader.load(Const.IMAGE_HEAD + listGuessInfo.get(position).getMain_img(), viewHolder.guessBook);
        return convertView;
    }

    public class ViewHolder {
        TextView guessName, guessPrice;
        ImageView guessBook;
    }
}
